package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.CmsGuest;
import com.example.demo.common.Response;
import com.example.demo.service.CmsFoodService;
import com.example.demo.service.CmsGuestService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "旅客管理服务")
@RestController
@RequestMapping("/guest")
public class CmsGuestController {
	
	@Autowired
	CmsGuestService guestService;
	
	@Autowired
	CmsFoodService foodService;
	
	@ApiOperation(value = "旅客入住")
	@PostMapping("/insert")
	public Response<String> insertData(CmsGuest guest){
		int k = guestService.insert(guest);
		if(k==1)return Response.ok("success");
		else if(k==0)return Response.error("房间已满");
		else return Response.error("idCard错误");
	}
	
	@ApiOperation(value = "旅客用餐")
	@GetMapping("/guestPurchase")
	public Response<String> guestPurchase(String idCard,String id,int num1){
		int i =guestService.guestPurchase(idCard, id, num1);
	    if(i==1) {
			return Response.ok("success");
		}
		    else return Response.ok("false");
		}
	
	@ApiOperation(value = "按身份证来删除旅客数据")	
	@DeleteMapping("/deleteById")
	public Response<String> deleteById(String id){
		int count = guestService.deleteById(id);
		return Response.ok("删除成功了"+count);
	}
	
	@ApiOperation(value = "按身份证来找出旅客数据")
	@GetMapping("/select")
	public Response<CmsGuest> selectById(String id){
		if(global.key==1) {
		CmsGuest data = guestService.selectById(id);
		return Response.ok(data);}
		return Response.error(null);
	}
	
	@ApiOperation(value = "列出所有旅客数据")
	@GetMapping("/All")
	public Response<List<CmsGuest>> findAll(){
		if(global.key==1) {
		List<CmsGuest> all = guestService.findAll();
		return Response.ok(all);}
		return Response.error(null);
	}
	
}
